#include "usarttransmitter.h"
#include "usart.h"

#define MAX_BUFFER_NUM			4
#define MAX_ARRAY_NUM			32

static uint8_t pos = 0;
static uint8_t base_pos = 0;
static uint8_t usartbuff[MAX_BUFFER_NUM][MAX_ARRAY_NUM] = {0};

void ClearUsart1Buffer(void)
{
	base_pos=pos;
}

void UsartBufferPush(uint8_t* buf,uint16_t len)
{
	uint8_t x = 0;
	if(len>MAX_ARRAY_NUM)
	{
		return ;
	}
	usartbuff[pos][0] = len;
	for(x=0;x<len;x++)
	{
		usartbuff[pos][x+1] = buf[x];
	}
	pos++;
	if(pos>=MAX_BUFFER_NUM)
	{
		pos=0;
	}
	if(pos==base_pos)
	{
		base_pos++;
		if(base_pos>=MAX_BUFFER_NUM)
		{
			base_pos=0;
		}
	}
}

void Usart_Send(void)
{
	if(pos==base_pos)
	{
		return ;
	}
	send_data_dma_u1(usartbuff[base_pos]+1,usartbuff[base_pos][0]);
	base_pos++;
	if(base_pos>=MAX_BUFFER_NUM)
	{
		base_pos=0;
	}
}


